const keyPrefix = 'tjj-nb-666'

function loadFromStorage(key, defaultValue) {
    key = `${keyPrefix}-${key}`
    let temp = localStorage.getItem(key)
    // if (key === 'tjj-nb-666-database') temp = null
    const value = temp ? JSON.parse(temp) : (defaultValue instanceof Function ? defaultValue() : defaultValue)
    window.addEventListener("beforeunload", () => {
        localStorage.setItem(key, JSON.stringify(value))
    })
    return value
}

export default loadFromStorage